var user = {
    /**
     * Create the authorization token if the request is valid
     */
    authorize: function(event) {
        event.preventDefault();
        dialog.show("Signing in");
        
        var isValidIO = true;
        var emptyIO = '';
        
        $(this).find("input").blur();
        
        $(this).find("input").each(function() {
            if ($(this).val().match(/^\s+$/)) {
                emptyIO = $(this).attr("id");
                isValidIO = false;
                return false;
            } else if ($(this).val().length == 0) {
                emptyIO = $(this).attr("id");
                isValidIO = false;
                return false;
            }
            return true;
        });
        
        if (isValidIO) {
            var options = buildDataString({
                authID: $("#key").val(),
                password: $("#password").val()
            });
            call("sessions?signin", options,
                function(response) {
                    userID = $("user username", response).text();
                    userRealName = $("user realname", response).text();
                    dialog.show(dictionary.locale.message.event.signInAs(userID), true, false,
                        function() {
                            ui.state.userAuthorizationGranted();
                        }
                    );
                },
                function(response) {
                    dialog.show(dictionary.locale.message.error.failedToSignIn, true);
                },
                "post"
            );
        } else {
            dialog.show("Wait... Something is missing?", true, true, function() {
                $("#signin input#" + emptyIO).focus();
            });
        }
        return false;
    },
    /**
     * @returns {string} username
     */
    authorized: function() {
        var ret = '';
        // *userID* is global defined by *server engine*
        if (userID != "") {
            ret = userID
        }
        return ret;
    },
    /**
     * Remove the authorization token if the request is valid
     */
    removeAuthorization: function(event) {
        event.preventDefault();
        dialog.show(dictionary.locale.message.event.signingOut);
        
        call("sessions", {},
            function(response) {
                userID = null;
                ui.state.userAuthorizationDenied();
                dialog.show(dictionary.locale.message.event.signedOut, true);
            }, null, "delete"
        );
        return false;
    }
}